/*
 * libjingle
 * Copyright 2004--2005, Google Inc.
 */

#ifndef _XMPPSOCKET_H_
#define _XMPPSOCKET_H_

#include "base/asyncsocket.h"
#include "base/bytebuffer.h"
#include "base/sigslot.h"
#include "xmpp/asyncsocket.h"

extern talk_base::AsyncSocket* cricket_socket_;

class XmppSocket : public buzz::AsyncSocket, public sigslot::has_slots<> {
public:
  XmppSocket(bool tls);
  ~XmppSocket();

  virtual buzz::AsyncSocket::State state();
  virtual buzz::AsyncSocket::Error error();
  virtual int GetError();

  virtual bool Connect(const talk_base::SocketAddress& addr);
  virtual bool Read(char * data, size_t len, size_t* len_read);
  virtual bool Write(const char * data, size_t len);
  virtual bool Close();
  virtual bool StartTls(const std::string & domainname);

private:
  void OnReadEvent(talk_base::AsyncSocket * socket);
  void OnWriteEvent(talk_base::AsyncSocket * socket);
  void OnConnectEvent(talk_base::AsyncSocket * socket);

  talk_base::AsyncSocket * cricket_socket_;
  buzz::AsyncSocket::State state_;
  talk_base::ByteBuffer buffer_;
  bool tls_;
};

#endif // _XMPPSOCKET_H_
